﻿#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define NAME "fasd.htf"

int WriteDefaultData();

int LoadKiroku(int data[])
{
	FILE *fp;

	char *ch;
	char dat[50];
	int i=0;

	fp=fopen(NAME , "r");

	if(fp==NULL){
		WriteDefaultData();
		fp=fopen(NAME , "r");
	}

	fgets(dat , sizeof(dat) , fp);

	ch=strtok(dat , ",\n");

	for(i=0;i<10;i++){

		if(ch==NULL){
			break;
		} else{
			data[i]=atoi(ch);
		}
		ch=strtok(NULL, ",\n");
	}

	fclose(fp);

	return 0;
}


//デフォのセーブデータを保存
int WriteDefaultData()
{

	FILE *fp;
	int tmp[10]={10,9,8,7,6,5,4,3,2,1};
	int i=0;


	fp=fopen(NAME , "w");

	for(i=0;i<10;i++){
		fprintf(fp , "%d,",tmp[i]);
	}

	fclose(fp);
	return 0;
}
